// pages/index/operationRecord/operationRecord.js
import Http from '../../../utils/http.js';

const http = new Http();
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        pageNum: 0,
        // fromWhere '00'主页进去，'01'秘书团进入
        fromWhere: '',
        loading: true,
        loadingAll: false,
        // 打卡记录数组
        records: [],
        //操作记录
        operationRecord: [],
        operationRecordBg: [], //缓存
        noInfo: false,
        powerMoreInfo: true, //是否有权限查看更多
        indexSize: -1, //增加阅读量表记位
        idSize: '',
    },
    jumpInfotap(e) {
        this.setData({
            indexSize: e.currentTarget.dataset.index,
            idSize: e.currentTarget.dataset.id,
        });
        wx.navigateTo({
            url: e.currentTarget.dataset.url,
        });
    },
    // 查看他人主页
    jumpOthersPage(e) {
        if (e.currentTarget.dataset.anonymousflg != '01') {
            wx.navigateTo({
                url: `/functionPage/pages/othersHomePage/othersHomePage?uid=${e.currentTarget.dataset.uid}`,
            });
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData(
            {
                fromWhere: options.fromWhere,
                operationRecordBg: wx.getStorageSync('operationRecordBg'),
            },
            () => {
                this.getOperationList();
            }
        );
        wx.showLoading({
            title: '加载中',
        });
        // wx.setNavigationBarTitle({
        //     title: options.title,
        // });
    },
    onShow: function (options) {
        if (this.data.indexSize >= 0) {
            this.refreshOperationList();
        }
    },

    previewImgTap(e) {
        if (
            e.currentTarget.dataset.type != '01' &&
            e.currentTarget.dataset.type != '02' &&
            e.currentTarget.dataset.type != '03' &&
            e.currentTarget.dataset.type != '04'
        ) {
            // this.setData({
            //     sceneImageArr: e.currentTarget.dataset.srcarr,
            //     description: e.currentTarget.dataset.descarr,
            // })
            // //hideBottom隐藏图片预览的删除按钮
            // wx: wx.navigateTo({
            //     url: `../../checkIn/imgPreview/imgPreview?hideBottom=${true}`,
            // })
            // 预览图片
            wx.previewImage({
                current: e.currentTarget.dataset.srcarr[0],
                urls: e.currentTarget.dataset.srcarr,
            });
        } else {
            wx.navigateTo({
                url: e.currentTarget.dataset.url,
            });
        }
    },
    getInfo() {
        if (this.data.fromWhere == '01') {
            this.getRecords();
        } else {
            this.getOperationList();
        }
    },
    // 获取首页记录列表
    getOperationList() {
        let _that = this;
        if (
            app.globalData.authority == '00' ||
            app.globalData.authority == '01' ||
            app.globalData.authority == '04' ||
            app.globalData.authority == '05' ||
            app.globalData.authority == '06' ||
            app.globalData.authority == '09'
        ) {
            if (!_that.data.loadingAll) {
                _that.setData({
                    pageNum: _that.data.pageNum + 1,
                    loading: true,
                    loadingAll: false,
                });
                wx.request({
                    url: app.globalData.rootPath + 'code/getOperationMsgList',
                    header: {
                        'content-type': 'application/json',
                    },
                    data: {
                        pageSize: 15,
                        pageNo: _that.data.pageNum,
                        mode: '01',
                        authId: app.globalData.authId,
                    },
                    success(res) {
                        if (res.data.status == 0) {
                            console.log(res.data.data);
                            for (let i = 0; i < res.data.data.length; i++) {
                                res.data.data[i].createtime = app.timeago(
                                    res.data.data[i].createtime
                                );
                                let picurlArr;
                                let title = '';
                                let url = '';
                                if (res.data.data[i].type == '01') {
                                    picurlArr = [
                                        'https://static.map8.com/sp/20200422/0_110800938671.jpg',
                                    ];
                                    title = res.data.data[i].fsl_operator
                                        ? res.data.data[i].fsl_operator +
                                          '：' +
                                          res.data.data[i].fsl_networkscene
                                        : res.data.data[i].fsl_networkscene;
                                    url = `../../homePageInfo/ftInfo/ftInfo?review=02&id=${res.data.data[i].id}`;
                                } else if (res.data.data[i].type == '02') {
                                    if (res.data.data[i].ntp_type == '01') {
                                        title =
                                            '易出问题点：' +
                                            res.data.data[i].ntp_pointname;
                                    } else {
                                        title =
                                            '钱包消费点：' +
                                            res.data.data[i].ntp_pointname;
                                    }
                                    picurlArr = [
                                        'https://static.map8.com/sp/20200422/0_110800705856.jpg',
                                    ];
                                    url = `../../homePageInfo/nfcInfo/nfcInfo?review=02&id=${res.data.data[i].id}`;
                                } else {
                                    if (res.data.data[i].type == '03') {
                                        url = `../../homePageInfo/ftRouteInfo/ftRouteInfo?review=02&id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '04') {
                                        url = `../../homePageInfo/nfcRouteInfo/nfcRouteInfo?review=02&id=${res.data.data[i].id}`;
                                    } else if (
                                        res.data.data[i].type == '05' &&
                                        res.data.data[i].mc_mode == '00'
                                    ) {
                                        url = `../../../functionPage/pages/minePage/checkInIfo/checkInIfo?navbtn=01&id=${res.data.data[i].id}`;
                                        res.data.data[i].checkValue = res.data
                                            .data[i].mc_description
                                            ? '：' +
                                              res.data.data[i].mc_description
                                            : '';
                                    } else if (res.data.data[i].type == '06') {
                                        url = `../../../functionPage/pages/secretary/noticeInfo/noticeInfo?id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '07') {
                                        url = `../../notice/projectNotice/projectNotice?id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '08') {
                                        url = `../../notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer?navbtn=01&id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '09') {
                                        url = `../../notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer?navbtn=01&id=${res.data.data[i].pa_pjquestionid}`;
                                    } else if (res.data.data[i].type == '10') {
                                        url = `../../../functionPage/pages/experienceDetail/experienceDetail?navbtn=01&review=02&id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '11') {
                                        url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=01`;
                                    } else if (res.data.data[i].type == '12') {
                                        url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=03`;
                                    } else if (res.data.data[i].type == '13') {
                                        url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=04`;
                                    } else if (res.data.data[i].type == '14') {
                                        url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=02`;
                                    } else if (res.data.data[i].type == '15') {
                                        url = `../../homePageInfo/business-hall/business-hall?navbtn=01&review=02&id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '16') {
                                        url = `../../../functionPage/pages/secretary/questionInfo/questionInfo?navbtn=01&review=02&id=${res.data.data[i].id}`;
                                    } else if (res.data.data[i].type == '17') {
                                        url = `../../../functionPage/pages/secretary/questionInfo/questionInfo?navbtn=01&review=02&id=${res.data.data[i].ca_cityquestionid}`;
                                    }
                                    picurlArr =
                                        res.data.data[i].cn_picurl ||
                                        res.data.data[i].mc_picurl ||
                                        res.data.data[i].ft_picurl ||
                                        res.data.data[i].nt_picurl ||
                                        res.data.data[i].tb_picurl;
                                    picurlArr = picurlArr
                                        ? JSON.parse(picurlArr)
                                        : [];
                                }
                                let content = '';
                                content =
                                    res.data.data[i].fsl_scenedescription ||
                                    res.data.data[i].pn_title ||
                                    res.data.data[i].cn_content ||
                                    res.data.data[i].pa_content ||
                                    res.data.data[i].pq_title ||
                                    res.data.data[i].ee_content ||
                                    res.data.data[i].fsl_networkscene ||
                                    res.data.data[i].ntp_description ||
                                    res.data.data[i].cq_description ||
                                    res.data.data[i].ca_content ||
                                    res.data.data[i].ta_excontent ||
                                    res.data.data[i].trans_excontent ||
                                    res.data.data[i].tt_excontent ||
                                    res.data.data[i].tf_excontent;
                                let readNum =
                                    res.data.data[i].fsl_browsenum ||
                                    res.data.data[i].ntp_browsenum ||
                                    res.data.data[i].ft_browsenum ||
                                    res.data.data[i].nt_browsenum ||
                                    res.data.data[i].mc_browsenum ||
                                    res.data.data[i].cn_browsenum ||
                                    res.data.data[i].pn_browsenum ||
                                    res.data.data[i].pq_browsenum ||
                                    res.data.data[i].pa_browsenum ||
                                    res.data.data[i].ee_browsenum ||
                                    res.data.data[i].trans_browsenum ||
                                    res.data.data[i].ta_browsenum ||
                                    res.data.data[i].tt_browsenum ||
                                    res.data.data[i].tf_browsenum ||
                                    res.data.data[i].tb_browsenum ||
                                    res.data.data[i].cq_browsenum ||
                                    res.data.data[i].ca_browsenum ||
                                    0;
                                res.data.data[i].readNum = readNum;
                                res.data.data[i].picurl = picurlArr;
                                res.data.data[i].content = content;
                                res.data.data[i].title = title;
                                res.data.data[i].url = url;
                                _that.data.operationRecord.push(
                                    res.data.data[i]
                                );
                            }
                            if (_that.data.pageNum == 1) {
                                wx.setStorageSync(
                                    'operationRecordBg',
                                    res.data.data
                                );
                            }
                            _that.setData(
                                {
                                    operationRecord: _that.data.operationRecord,
                                    loading: false,
                                },
                                () => {
                                    wx.hideLoading();
                                }
                            );
                            if (
                                res.data.data.length ==
                                res.data.pager.totalRows - 1
                            ) {
                                _that.setData({
                                    loadingAll: true,
                                });
                            } else {
                                _that.setData({
                                    noInfo: true,
                                });
                            }
                            console.log(_that.data.operationRecord);
                        } else {
                            if (res.data.errmsg == '输入页码超出范围') {
                                _that.setData({
                                    loadingAll: true,
                                    loading: false,
                                });
                            }
                        }
                    },
                });
            }
        } else {
            wx.request({
                url: app.globalData.rootPath + 'code/getOperationMsgList',
                header: {
                    'content-type': 'application/json',
                },
                data: {
                    pageSize: 15,
                    pageNo: 1,
                    authId: app.globalData.authId,
                },
                success(res) {
                    console.log(res.data.data);
                    for (let i = 0; i < res.data.data.length; i++) {
                        res.data.data[i].createtime = app.timeago(
                            res.data.data[i].createtime
                        );
                        let picurlArr;
                        let title = '';
                        let url = '';
                        if (res.data.data[i].type == '01') {
                            picurlArr = [
                                'https://static.map8.com/sp/20200422/0_110800938671.jpg',
                            ];
                            title = res.data.data[i].fsl_operator
                                ? res.data.data[i].fsl_operator +
                                  '：' +
                                  res.data.data[i].fsl_networkscene
                                : res.data.data[i].fsl_networkscene;
                            url = `../../homePageInfo/ftInfo/ftInfo?review=02&id=${res.data.data[i].id}`;
                        } else if (res.data.data[i].type == '02') {
                            if (res.data.data[i].ntp_type == '01') {
                                title =
                                    '易出问题点：' +
                                    res.data.data[i].ntp_pointname;
                            } else {
                                title =
                                    '钱包消费点：' +
                                    res.data.data[i].ntp_pointname;
                            }
                            picurlArr = [
                                'https://static.map8.com/sp/20200422/0_110800705856.jpg',
                            ];
                            url = `../../homePageInfo/nfcInfo/nfcInfo?review=02&id=${res.data.data[i].id}`;
                        } else {
                            if (res.data.data[i].type == '03') {
                                url = `../../homePageInfo/ftRouteInfo/ftRouteInfo?review=02&id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '04') {
                                url = `../../homePageInfo/nfcRouteInfo/nfcRouteInfo?review=02&id=${res.data.data[i].id}`;
                            } else if (
                                res.data.data[i].type == '05' &&
                                res.data.data[i].mc_mode == '00'
                            ) {
                                url = `../../../functionPage/pages/minePage/checkInIfo/checkInIfo?navbtn=01&id=${res.data.data[i].id}`;
                                res.data.data[i].checkValue = res.data.data[i]
                                    .mc_description
                                    ? '：' + res.data.data[i].mc_description
                                    : '';
                            } else if (res.data.data[i].type == '06') {
                                url = `../../../functionPage/pages/secretary/noticeInfo/noticeInfo?id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '07') {
                                url = `../../notice/projectNotice/projectNotice?id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '08') {
                                url = `../../notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer?navbtn=01&id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '09') {
                                url = `../../notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer?navbtn=01&id=${res.data.data[i].pa_pjquestionid}`;
                            } else if (res.data.data[i].type == '10') {
                                url = `../../../functionPage/pages/experienceDetail/experienceDetail?navbtn=01&review=02&id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '11') {
                                url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=01`;
                            } else if (res.data.data[i].type == '12') {
                                url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=03`;
                            } else if (res.data.data[i].type == '13') {
                                url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=04`;
                            } else if (res.data.data[i].type == '14') {
                                url = `../../../functionPage/pages/cszxDetail/cszxDetail?navbtn=01&id=${res.data.data[i].id}&type=02`;
                            } else if (res.data.data[i].type == '15') {
                                url = `../../homePageInfo/business-hall/business-hall?navbtn=01&review=02&id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '16') {
                                url = `../../../functionPage/pages/secretary/questionInfo/questionInfo?navbtn=01&review=02&id=${res.data.data[i].id}`;
                            } else if (res.data.data[i].type == '17') {
                                url = `../../../functionPage/pages/secretary/questionInfo/questionInfo?navbtn=01&review=02&id=${res.data.data[i].ca_cityquestionid}`;
                            }

                            picurlArr =
                                res.data.data[i].cn_picurl ||
                                res.data.data[i].mc_picurl ||
                                res.data.data[i].ft_picurl ||
                                res.data.data[i].nt_picurl ||
                                res.data.data[i].tb_picurl;
                            picurlArr = picurlArr ? JSON.parse(picurlArr) : [];
                        }
                        let content = '';
                        content =
                            res.data.data[i].fsl_scenedescription ||
                            res.data.data[i].pn_title ||
                            res.data.data[i].cn_content ||
                            res.data.data[i].pa_content ||
                            res.data.data[i].pq_title ||
                            res.data.data[i].ee_content ||
                            res.data.data[i].fsl_networkscene ||
                            res.data.data[i].ntp_description ||
                            res.data.data[i].cq_description ||
                            res.data.data[i].ca_content ||
                            res.data.data[i].ta_excontent ||
                            res.data.data[i].trans_excontent ||
                            res.data.data[i].tt_excontent ||
                            res.data.data[i].tf_excontent;
                        let readNum =
                            res.data.data[i].fsl_browsenum ||
                            res.data.data[i].ntp_browsenum ||
                            res.data.data[i].ft_browsenum ||
                            res.data.data[i].nt_browsenum ||
                            res.data.data[i].mc_browsenum ||
                            res.data.data[i].cn_browsenum ||
                            res.data.data[i].pn_browsenum ||
                            res.data.data[i].pq_browsenum ||
                            res.data.data[i].pa_browsenum ||
                            res.data.data[i].ee_browsenum ||
                            res.data.data[i].trans_browsenum ||
                            res.data.data[i].ta_browsenum ||
                            res.data.data[i].tt_browsenum ||
                            res.data.data[i].tf_browsenum ||
                            res.data.data[i].tb_browsenum ||
                            res.data.data[i].cq_browsenum ||
                            res.data.data[i].ca_browsenum ||
                            0;
                        res.data.data[i].readNum = readNum;
                        res.data.data[i].picurl = picurlArr;
                        res.data.data[i].content = content;
                        res.data.data[i].title = title;
                        res.data.data[i].url = url;
                        _that.data.operationRecord.push(res.data.data[i]);
                    }
                    wx.setStorageSync('operationRecordBg', res.data.data);
                    _that.setData(
                        {
                            operationRecord: res.data.data,
                            powerMoreInfo: false,
                        },
                        () => {
                            wx.hideLoading();
                        }
                    );
                },
            });
        }
    },
    //刷新浏览量
    refreshOperationList() {
        let _that = this;
        http.getRequest(
            `code/getOperationMsgList?authId=${
                app.globalData.authId
            }&pageSize=${_that.data.indexSize + 10}&pageNo=1&mode=01`
        ).then((res) => {
            if (res.status == 0) {
                console.log(res);
                for (let i = 0; i < res.data.length; i++) {
                    if (res.data[i].id == _that.data.idSize) {
                        let index = _that.data.indexSize;
                        _that.data.operationRecord[index].praiseCnt =
                            res.data[index].praiseCnt || 0;
                        _that.data.operationRecord[index].commentCnt =
                            res.data[index].commentCnt || 0;
                        _that.data.operationRecord[index].readflg =
                            res.data[index].readflg;
                        let readNum =
                            res.data[index].fsl_browsenum ||
                            res.data[index].ntp_browsenum ||
                            res.data[index].ft_browsenum ||
                            res.data[index].nt_browsenum ||
                            res.data[index].mc_browsenum ||
                            res.data[index].cn_browsenum ||
                            res.data[index].pn_browsenum ||
                            res.data[index].pq_browsenum ||
                            res.data[index].pa_browsenum ||
                            res.data[index].ee_browsenum ||
                            res.data[index].trans_browsenum ||
                            res.data[index].ta_browsenum ||
                            res.data[index].tt_browsenum ||
                            res.data[index].tf_browsenum ||
                            res.data[index].tb_browsenum ||
                            res.data[index].cq_browsenum ||
                            res.data[index].ca_browsenum;
                        _that.data.operationRecord[index].readNum = readNum;
                        _that.setData({
                            operationRecord: _that.data.operationRecord,
                        });
                    }
                }
            }
        });
    },
});
